unit FormCalcPrice;

interface

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls, cxControls, cxContainer, cxEdit, cxTextEdit,
    cxCurrencyEdit, DB, ADODB, ActnList, Math;

type
    TfrmCalcPrice = class(TForm)
        btnConvert: TButton;
        Label1: TLabel;
        Label2: TLabel;
        btnSave: TButton;
        eFullPrice: TcxCurrencyEdit;
        eVolume: TcxCurrencyEdit;
        ePrice: TcxCurrencyEdit;
        btnClose: TButton;
        Label3: TLabel;
        procedure btnConvertClick(Sender: TObject);
        procedure btnCloseClick(Sender: TObject);
        procedure btnSaveClick(Sender: TObject);
    private
        fresult_price: currency;
    public
        constructor Create(AOwner: TComponent; aFullPrice: currency; aCount: integer); reintroduce; overload;
        property result_price: currency read fresult_price;
    end;

var
    frmCalcPrice: TfrmCalcPrice;

implementation

uses DataModule;

{$R *.dfm}

constructor TfrmCalcPrice.Create(AOwner: TComponent; aFullPrice: currency; aCount: integer);
begin
    inherited Create(AOwner);
    fresult_price := -1;
    eVolume.Text := IntTostr(aCount);
    eFullPrice.Text := CurrToStr(aFullPrice);
    btnConvert.Click;
end;

procedure TfrmCalcPrice.btnConvertClick(Sender: TObject);
var
    c: Currency;
begin
    try
        c := StrToCurr(eFullPrice.Text) / StrToCurr(eVolume.Text);
        ePrice.Text := CurrToStr(c);
    except
        ePrice.Text := eFullPrice.Text;
    end;
end;

procedure TfrmCalcPrice.btnCloseClick(Sender: TObject);
begin
    fresult_price := -1;
    Close;
end;

procedure TfrmCalcPrice.btnSaveClick(Sender: TObject);
begin
    fresult_price := StrToFloat(ePrice.Text);
    Close;
end;

end.

